home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14718 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  60 lines

  1. Newsgroups: comp.lang.ada,comp.lang.c++
  2. Path: in2.uu.net!world!bobduff
  3. From: bobduff@world.std.com (Robert A Duff)
  4. Subject: Re: some questions re. Ada/GNAT from a C++/GCC user
  5. Message-ID: <Dp75DK.DMG@world.std.com>
  6. Organization: The World Public Access UNIX, Brookline, MA
  7. References: <wnewmanDoxrCp.DKv@netcom.com> <Dp1oAw.7Cz@world.std.com> <4jlj79$h1k@Nntp1.mcs.net>
  8. Date: Mon, 1 Apr 1996 18:44:08 GMT
  9.  
  10. In article <4jlj79$h1k@Nntp1.mcs.net>, Mike Young <mikey@mcs.com> wrote:
  11. >I'd been bemoaning the lack of iostreams in Ada. Would you elaborate (no pun 
  12. >intended) more on how "&" and 'Image would be used?
  13.  
  14. Well, I'm not sure exactly what you're asking.  To print stuff out, you
  15. need some procedure that prints text strings, and you need some way to
  16. convert whatever you want to print out into a text string.  In Ada,
  17. 'Image is used to convert simple data types like Integer and Float into
  18. human-readable Strings.  For complicated data types, you write your own
  19. Image function.  The "&" operator just concatenates Strings.  So to
  20. print out some stuff, you write:
  21.  
  22.     Put("X = " & Integer'Image(X) & "; and List = " & Image(List));
  23.  
  24. Where List is a variable of some complicated data structure.  This
  25. converts X and List to type String, concatenates the whole mess
  26. together, and prints it to standard output.
  27.  
  28. Does that answer your question?
  29.  
  30. >Yup. Good practice is not limited by choice of language, I see. :)
  31.  
  32. :-)
  33.  
  34. >The other sad part of function-like macros is safety of side-effects in macro 
  35. >arguments. ...
  36.  
  37. Indeed.
  38.  
  39. >In spite of this, macros are still the only way to perform some useful tasks. 
  40. >For example:
  41. >
  42. >#ifndef _DEBUG
  43. >#define assert(a)
  44. >#else
  45. >#define assert(a) {if (!a) {_assert_fail(__FILE__, __LINE__, #a);}}
  46. >#endif
  47. >
  48. >How would you do this in Ada?
  49.  
  50. I don't know of any way to do that in Ada.  However, that's not a huge
  51. problem.  You indicate a run-time error by raising an exception.  You
  52. can write an Assert procedure that checks the condition, and raises an
  53. exception if False.  Any reasonable debugger can tell you what line of
  54. code failed, and show you the line of code.  And any reasonable debugger
  55. can tell the difference between an exception that is handled, with
  56. intent to continue executing, and an exception that is unhandled, and is
  57. therefore just a bug.
  58.  
  59. - Bob
  60.